﻿singleApp.controller('reportsCtrl', ['$http', '$scope', '$sce', '$timeout', 'PageService', function ($http, $scope, $sce, $timeout, PageService) {
    $scope.list = [];
    $scope.Page = {
        pageindex: 1,
        pagesize: "10",
        from_user_name: "",
        to_user_name: "",
        TotalPages: 0,
        TotalRecords: 0,
        PageWindowSize: 10,
        PageRange: [],
    };

    //Init
    $scope.init = function () {
        layer.load(2);

        var parms = [];
        parms.push("pageindex=" + $scope.Page.pageindex);
        parms.push("pagesize=" + $scope.Page.pagesize);
        parms.push("from_user_name=" + $scope.Page.from_user_name);
        parms.push("to_user_name=" + $scope.Page.to_user_name);
        var api_url = window.singleConfig.rootUrl + "api/admin/UsersService/pageListReport?" + parms.join("&");

        $http.get(api_url).then(function (result) {
            var data = result.data;

            angular.forEach(data.records, function (item, index, array) {
                if (item.deal_time.indexOf('0000') != -1) {
                    item.deal_time = "";
                }
            });

            $scope.list = data.records;
            $scope.Page.TotalPages = data.totalPages;
            $scope.Page.TotalRecords = data.count;
            $scope.Page.PageRange = PageService.getPageRange($scope.Page.pageindex, $scope.Page.PageWindowSize, $scope.Page.TotalPages);
            layer.closeAll();
        }, function () { });
    };

    $scope.init();


    $scope.GoToPage = function (page) {
        if (page == $scope.Page.pageindex)
            return;
        $scope.Page.pageindex = page;
        $scope.init();
    };

    $scope.confirm = function (item) {
        if (item.status != "0")
            return;

        layer.confirm('已查看，并认同提交的信息？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            layer.load(2);
            var api_url = window.singleConfig.rootUrl + "api/user/CommonService/confirm_report?id=" + item.id;
            $http.get(api_url).then(function (result) {
                layer.closeAll();
                layer.msg("确认成功");
                $timeout(function () {
                    $scope.init();
                }, 1000);
            }, function () { });
        }, function () {

        });
    };

    $scope.search = function () {
        $scope.init();
    };
}]);